package com.milk.controller.user;

import com.milk.entity.Lottery;
import com.milk.entity.UserLottery;
import com.milk.result.Result;
import com.milk.service.LotteryService;
import com.milk.vo.UserLotteryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/lottery")
@Slf4j
public class LotteryController {
    @Autowired
    private LotteryService lotteryService;

    /**
     * 查找抽奖奖池
     * @return
     */
    @GetMapping
    private Result<List<Lottery>> selectAll(){
        List<Lottery> list = lotteryService.selectAll();
        return Result.success(list);
    }

    /**
     * 保存抽中的奖品
     * @param lottery
     * @return
     */
    @PostMapping
    private Result lotteryRecord(@RequestBody Lottery lottery){
        log.info("抽中奖品 = {}",lottery);
        lotteryService.lotteryRecord(lottery);
        return Result.success();
    }

    /**
     * 查询中奖记录
     * @return
     */
    @GetMapping("/record")
    private Result<List<UserLotteryVO>> selectRecord(){
        List<UserLotteryVO> list = lotteryService.selectRecord();
        return Result.success(list);
    }
}
